//
//  HPTwoTableViewCell.swift
//  TLenPoint
//
//  Created by Docker on 2018/3/28.
//  Copyright © 2018年 Docker. All rights reserved.
//

import UIKit

class HPTwoTableViewCell: UITableViewCell {

    //MARK: -- 初始化方法
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

    
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.creat()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: -- 创建UI
    func creat(){
        
        let imageArray = [["title":"练K场","image":"Home_Game_Practice_K"],["title":"短线场","image":"Home_Game_Simulate_Training"],["title":"国内场","image":"Home_Game_Domestic"],["title":"国际场","image":"Home_Game_Foreign"]]
       
        let width = ScranWidth/4
        for i in 0..<imageArray.count{
            let dict = imageArray[i] as [String:Any]
            let view = self.creatView(title: dict["title"] as! String, image: dict["image"] as! String)
            self.addSubview(view)
            view.snp.makeConstraints({ (make) in
                make.left.equalToSuperview().offset(CGFloat(i)*width)
                make.top.equalToSuperview()
                make.bottom.equalToSuperview()
                make.width.equalTo(width)
            })
            view.tag = 100 + i
            let tap = UITapGestureRecognizer(target: self, action: #selector(tapAction(taps:)))
            view.addGestureRecognizer(tap)
        }
    }
    
    func creatView(title:String,image:String) -> UIView{
        let view = UIView()
        let imageView = UIImageView()
        imageView.image = UIImage(named: image)
        view.addSubview(imageView)
        imageView.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(13)
        }
        let label = UILabel()
        label.textColor = UIColor.black
        label.text = title
        label.font = UIFont.systemFont(ofSize: 13)
        view.addSubview(label)
        label.snp.makeConstraints { (make) in
            make.top.equalTo(imageView.snp.bottom).offset(8)
            make.centerX.equalToSuperview()
        }
        label.textAlignment = .center
        return view
    }
    
    //MARK: -- view点击
    @objc func tapAction(taps:UITapGestureRecognizer){
        
    }
}
